<%@LANGUAGE="VBSCRIPT"%>
 
<!--#include file="functions.asp" -->

<%
   dim tmpSQL
   if (request.querystring("InvStatus") <> "0") then
   tmpSQL=" AND STATUS='"& request.querystring("InvStatus") & "'"
   end if
   
   if (request.querystring("CurSymbol") <> "N") then
   tmpSQL= tmpSQL & " AND SYMBOL='"& request.querystring("CurSymbol") & "'"
   end if
   
   if (request.querystring("VendorID") <> "") then
   tmpSQL= tmpSQL & " AND VENDORID='"& request.querystring("VendorID") & "'"
   end if
   
   dim tmpSort
   tmpSort="INVDATE"
   if (request.querystring("dSort") <> "") then
   tmpSort= request.querystring("dSort")
   end if
   
   dim tmpOrder
   tmpOrder = "ASC"
   if (request.QueryString("dOrder") <>"") then
   tmpOrder= request.QueryString("dOrder")
   end if
   Dim CurrOrder
   if (tmpOrder = "ASC" )then 
   CurrOrder ="DESC"
   else
   CurrOrder="ASC"
   end if

%>
<%
Dim LVO__tmpCode
LVO__tmpCode = "''"
if (empCode <> "") then LVO__tmpCode = empCode
%>
<%
set LVO = Server.CreateObject("ADODB.Recordset")
LVO.ActiveConnection = cn
if (isUC="Y") then
LVO.Source = "SELECT LVONUM,REGNUM, INVNUM, VENDORID,STATUS,SUBTOTAL, SYMBOL, INVDATE, PAYMENTDATE, DUEDATE,  (SELECT LOCNAME=CASE WHEN LASTNAME IS NOT NULL THEN EMP.FIRSTNAME + ' '  + EMP.LASTNAME WHEN LASTNAME IS NULL THEN EMP.FIRSTNAME END FROM dbo.EMP WHERE EMP.EMPCODE=EXILVOHEADER.ROUTEUSER) AS LOCNAME, (SELECT TOP 1  VENDOR.NAME FROM VENDOR WHERE VENDOR.VENDORID=EXILVOHEADER.VENDORID) AS VENDORNAME, ISOPEN  FROM dbo.EXILVOHEADER  WHERE  (STATUS = 'APPROVED' OR STATUS='PAID' OR STATUS='ROUTED') AND (UCCODE='" + Replace(LVO__tmpCode, "'", "''") + "' OR INVAPPR='" + Replace(LVO__tmpCode, "'", "''") + "' OR INVVER='" + Replace(LVO__tmpCode, "'", "''") + "')"
else
LVO.Source = "SELECT LVONUM,REGNUM, INVNUM, VENDORID,STATUS,SUBTOTAL, SYMBOL, INVDATE, PAYMENTDATE, DUEDATE,  (SELECT LOCNAME=CASE WHEN LASTNAME IS NOT NULL THEN EMP.FIRSTNAME + ' '  + EMP.LASTNAME WHEN LASTNAME IS NULL THEN EMP.FIRSTNAME END FROM dbo.EMP WHERE EMP.EMPCODE=EXILVOHEADER.ROUTEUSER) AS LOCNAME, (SELECT TOP 1  VENDOR.NAME FROM VENDOR WHERE VENDOR.VENDORID=EXILVOHEADER.VENDORID) AS VENDORNAME, ISOPEN  FROM dbo.EXILVOHEADER  WHERE (STATUS = 'APPROVED' OR STATUS='PAID' OR STATUS='ROUTED' ) AND (INVAPPR='" + Replace(LVO__tmpCode, "'", "''") + "' OR INVVER='" + Replace(LVO__tmpCode, "'", "''") + "')"
end if
'LVO.CursorType = 0
'LVO.CursorLocation = 2
'LVO.LockType = 3
LVO.Open()
LVO_numRows = 0
%>
<%
Dim Repeat2__numRows
Repeat2__numRows = 20
Dim Repeat2__index
Repeat2__index = 0
LVO_numRows = LVO_numRows + Repeat2__numRows
%>
<%
'  *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

' set the record count
LVO_total = LVO.RecordCount

' set the number of rows displayed on this page
If (LVO_numRows < 0) Then
  LVO_numRows = LVO_total
Elseif (LVO_numRows = 0) Then
  LVO_numRows = 1
End If

' set the first and last displayed record
LVO_first = 1
LVO_last  = LVO_first + LVO_numRows - 1

' if we have the correct record count, check the other stats
If (LVO_total <> -1) Then
  If (LVO_first > LVO_total) Then LVO_first = LVO_total
  If (LVO_last > LVO_total) Then LVO_last = LVO_total
  If (LVO_numRows > LVO_total) Then LVO_numRows = LVO_total
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them

If (LVO_total = -1) Then

  ' count the total records by iterating through the recordset
  LVO_total=0
  While (Not LVO.EOF)
    LVO_total = LVO_total + 1
    LVO.MoveNext
  Wend

  ' reset the cursor to the beginning
  If (LVO.CursorType > 0) Then
    LVO.MoveFirst
  Else
    LVO.Requery
  End If

  ' set the number of rows displayed on this page
  If (LVO_numRows < 0 Or LVO_numRows > LVO_total) Then
    LVO_numRows = LVO_total
  End If

  ' set the first and last displayed record
  LVO_first = 1
  LVO_last = LVO_first + LVO_numRows - 1
  If (LVO_first > LVO_total) Then LVO_first = LVO_total
  If (LVO_last > LVO_total) Then LVO_last = LVO_total

End If
%>
<%
' *** Move To Record and Go To Record: declare variables

Set MM_rs    = LVO
MM_rsCount   = LVO_total
MM_size      = LVO_numRows
MM_uniqueCol = ""
MM_paramName = ""
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
  MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%>
<%
' *** Move To Record: handle 'index' or 'offset' parameter

if (Not MM_paramIsDefined And MM_rsCount <> 0) then

  ' use index parameter if defined, otherwise use offset parameter
  r = Request.QueryString("index")
  If r = "" Then r = Request.QueryString("offset")
  If r <> "" Then MM_offset = Int(r)

  ' if we have a record count, check if we are past the end of the recordset
  If (MM_rsCount <> -1) Then
    If (MM_offset >= MM_rsCount Or MM_offset = -1) Then  ' past end or move last
      If ((MM_rsCount Mod MM_size) > 0) Then         ' last page not a full repeat region
        MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
      Else
        MM_offset = MM_rsCount - MM_size
      End If
    End If
  End If

  ' move the cursor to the selected record
  i = 0
  While ((Not MM_rs.EOF) And (i < MM_offset Or MM_offset = -1))
    MM_rs.MoveNext
    i = i + 1
  Wend
  If (MM_rs.EOF) Then MM_offset = i  ' set MM_offset to the last possible record

End If
%>
<%
' *** Move To Record: if we dont know the record count, check the display range

If (MM_rsCount = -1) Then

  ' walk to the end of the display range for this page
  i = MM_offset
  While (Not MM_rs.EOF And (MM_size < 0 Or i < MM_offset + MM_size))
    MM_rs.MoveNext
    i = i + 1
  Wend

  ' if we walked off the end of the recordset, set MM_rsCount and MM_size
  If (MM_rs.EOF) Then
    MM_rsCount = i
    If (MM_size < 0 Or MM_size > MM_rsCount) Then MM_size = MM_rsCount
  End If

  ' if we walked off the end, set the offset based on page size
  If (MM_rs.EOF And Not MM_paramIsDefined) Then
    If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then
      If ((MM_rsCount Mod MM_size) > 0) Then
        MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
      Else
        MM_offset = MM_rsCount - MM_size
      End If
    End If
  End If

  ' reset the cursor to the beginning
  If (MM_rs.CursorType > 0) Then
    MM_rs.MoveFirst
  Else
    MM_rs.Requery
  End If

  ' move the cursor to the selected record
  i = 0
  While (Not MM_rs.EOF And i < MM_offset)
    MM_rs.MoveNext
    i = i + 1
  Wend
End If
%>
<%
' *** Move To Record: update recordset stats

' set the first and last displayed record
LVO_first = MM_offset + 1
LVO_last  = MM_offset + MM_size
If (MM_rsCount <> -1) Then
  If (LVO_first > MM_rsCount) Then LVO_first = MM_rsCount
  If (LVO_last > MM_rsCount) Then LVO_last = MM_rsCount
End If

' set the boolean used by hide region to check if we are on the last record
MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then MM_removeList = MM_removeList & "&" & MM_paramName & "="
MM_keepURL="":MM_keepForm="":MM_keepBoth="":MM_keepNone=""

' add the URL parameters to the MM_keepURL string
For Each Item In Request.QueryString
  NextItem = "&" & Item & "="
  If (InStr(1,MM_removeList,NextItem,1) = 0) Then
    MM_keepURL = MM_keepURL & NextItem & Server.URLencode(Request.QueryString(Item))
  End If
Next

' add the Form variables to the MM_keepForm string
For Each Item In Request.Form
  NextItem = "&" & Item & "="
  If (InStr(1,MM_removeList,NextItem,1) = 0) Then
    MM_keepForm = MM_keepForm & NextItem & Server.URLencode(Request.Form(Item))
  End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
if (MM_keepBoth <> "") Then MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
if (MM_keepURL <> "")  Then MM_keepURL  = Right(MM_keepURL, Len(MM_keepURL) - 1)
if (MM_keepForm <> "") Then MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
  If (firstItem <> "") Then
    MM_joinChar = "&"
  Else
    MM_joinChar = ""
  End If
End Function
%>
<%
' *** Move To Record: set the strings for the first, last, next, and previous links

MM_keepMove = MM_keepBoth
MM_moveParam = "index"

' if the page has a repeated region, remove 'offset' from the maintained parameters
If (MM_size > 0) Then
  MM_moveParam = "offset"
  If (MM_keepMove <> "") Then
    params = Split(MM_keepMove, "&")
    MM_keepMove = ""
    For i = 0 To UBound(params)
      nextItem = Left(params(i), InStr(params(i),"=") - 1)
      If (StrComp(nextItem,MM_moveParam,1) <> 0) Then
        MM_keepMove = MM_keepMove & "&" & params(i)
      End If
    Next
    If (MM_keepMove <> "") Then
      MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)
    End If
  End If
End If

' set the strings for the move to links
If (MM_keepMove <> "") Then MM_keepMove = MM_keepMove & "&"
urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="
MM_moveFirst = urlStr & "0"
MM_moveLast  = urlStr & "-1"
MM_moveNext  = urlStr & Cstr(MM_offset + MM_size)
prev = MM_offset - MM_size
If (prev < 0) Then prev = 0
MM_movePrev  = urlStr & Cstr(prev)
%>
<SCRIPT Language="JavaScript">
var InvNum='<%= request.querystring("InvNum") %>';
var InvStatus='<%= request.querystring("InvStatus") %>';
var dsort='<%= request.querystring("dsort") %>';
var dorder='<%= request.querystring("dorder") %>';
var VendorID='<%= request.querystring("VendorID") %>';
var CurSymbol='<%= request.querystring("CurSymbol") %>';

function DocLoad(){

}

function DoSort(dtsort,dtorder) {
//alert (link.id);
//location = link.href;
document.form1.dsort.value=dtsort;
document.form1.dorder.value=dtorder;
document.form1.submit();
return false;
}

function redirect(which){
location='my_InvoiceLVODet.asp?LVONum='+which+'&InvNum='+InvNum+'&InvStatus='+InvStatus+'&dsort='+ dsort+'&dorder='+ dorder+'&VendorID='+VendorID+'&CurSymbol='+CurSymbol;
return false
}

function doClear(){
location='my_InvLVO_list.asp?InvStatus=0&CurSymbol=N';
return false
}

function doSearch(){
location='my_InvSearchLVO.asp?InvNum='+InvNum+'&InvStatus='+InvStatus+'&dsort='+ dsort+'&dorder='+ dorder+'&VendorID='+VendorID+'&CurSymbol='+CurSymbol;
return false
}
</SCRIPT>
<!-- #include file="pagetop_usr.asp" -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td nowrap height="21" bgcolor="#FFFFFF" width="3%" background="images/menu_end.gif">&nbsp;</td>
    <td nowrap height="21" bgcolor="#FFFFFF" width="28"> 
      <div align="center"><img src="images/menu_awal_off.gif" width="28" height="33"></div>
    </td>
    <td width="15%" background="images/menuoff.gif" height="21" nowrap> 
      <div align="center"><b><a href="My_invoice.asp" class="menu">My Invoice</a></b></div>
    </td>
    <td width="28" height="21" nowrap><img src="images/menu_off_on_separator.gif" width="28" height="33"></td>
    <td width="15%" background="images/menuon.gif" height="21" nowrap> 
      <div align="center" class="menu">My Invoice Archive</div>
    </td>
    <td height="21" bgcolor="#FFFFFF" width="11"><img src="images/Menu_onend.gif" width="13" height="33"></td>
    <td height="21" bgcolor="#FFFFFF" background="images/menu_end.gif"> 
      <div align="right"></div>
    </td>
  </tr>
  <tr bgcolor="#93bee2"> 
    <td width="3%" bgcolor="#93bee2">&nbsp;</td>
    <td width="28" bgcolor="#93bee2">&nbsp;</td>
    <td width="10%" bgcolor="#93bee2">&nbsp;</td>
    <td width="28" bgcolor="#93bee2">&nbsp;</td>
    <td width="10%" bgcolor="#93bee2">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#93bee2">
  <tr> 
    <td width="4%">&nbsp;</td>
    <td width="2%">&nbsp;</td>
    <td>
      <form name="form1" method="post" action="">
        <input type="radio" name="radiobutton" value="radiobutton" onClick="window.location='my_invoice_List.asp?InvStatus=0&RefOrder=0&CurSymbol=N'">
        Invoices With Reference Order 
        <input type="radio" name="radiobutton" value="radiobutton" checked>
        LVO Invoices &nbsp;&nbsp; 
        <input type="button" name="Button" value="Search..." class="sbttn" onClick="doSearch()">
        <input type="button" name="Button" value="Clear Search" class="sbttn" onClick="doClear()">
        <input type="hidden" name="InvNum" value="<%= request.querystring("InvNum") %>">
        <input type="hidden" name="InvStatus" value="<%= request.querystring("InvStatus") %>">
        <input type="hidden" name="VendorID" value="<%= request.querystring("VendorID") %>">
        <input type="hidden" name="CurSymbol" value="<%= request.querystring("CurSymbol") %>">
        <input type="hidden" name="dsort" value="<%= Request.querystring("dsort") %>">
        <input type="hidden" name="dorder" value="<%= Request.querystring("dorder") %>">
      </form>
    </td>
  </tr>
  <tr> 
    <td width="4%">&nbsp;</td>
    <td width="2%">&nbsp;</td>
    <td> 
      <table border="0" width="70%" align="center">
        <tr> 
          <td width="23%" align="center"> <b> 
            <% If MM_offset <> 0 Then %>
            <a href="<%=MM_moveFirst%>">&lt;&lt; First</a> 
            <% End If ' end MM_offset <> 0 %>
            </b></td>
          <td width="31%" align="center"> <b> 
            <% If MM_offset <> 0 Then %>
            <a href="<%=MM_movePrev%>">&lt; Previous</a> 
            <% End If ' end MM_offset <> 0 %>
            </b></td>
          <td width="23%" align="center"> <b> 
            <% If Not MM_atTotal Then %>
            <a href="<%=MM_moveNext%>">Next &gt; </a> 
            <% End If ' end Not MM_atTotal %>
            </b></td>
          <td width="23%" align="center"> <b> 
            <% If Not MM_atTotal Then %>
            <a href="<%=MM_moveLast%>">Last &gt;&gt; </a> 
            <% End If ' end Not MM_atTotal %>
            </b></td>
        </tr>
      </table>
 
    </td>
  </tr>
  <tr> 
    <td width="4%" height="20">&nbsp;</td>
    <td width="2%" bgcolor="#FFFFFF" height="20"><img src="images/curv_data.gif" width="21" height="21"></td>
    <td bgcolor="#FFFFFF" height="20"> <b>LVO Invoices</b></td>
  </tr>
  <tr> 
    <td width="4%" height="21">&nbsp;</td>
    <td width="2%" bgcolor="#FFFFFF" height="21">&nbsp;</td>
    <td bgcolor="#FFFFFF" height="21"> Records <%=(LVO_first)%> to <%=(LVO_last)%> 
      of <%=(LVO_total)%> </td>
  </tr>
  <tr> 
    <td width="4%">&nbsp;</td>
    <td width="2%" bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF"> 
      <table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#999999">
        <tr bgcolor="#D1DDEF" valign="middle"> 
          <td width="5%" height="25"> 
            <div align="center"><font color="#000066"><b>No.</b></font></div>
          </td>
          <td width="7%" height="25"> 
            <div align="center"><font color="#000066"><b>Reg. No </b></font></div>
          </td>
          <td width="10%" height="25"> 
            <div align="center"><font color="#000066"><b>Invoice No.</b></font></div>
          </td>
          <td width="9%" height="25"> 
            <div align="center"><font color="#000066"><b><a href="#" class="menu" onClick="return DoSort('LVONUM','<%= CurrOrder %>')">LVO 
              No</a> 
              <% if (tmpSort="LVONUM") then %>
              <img src="images/imgSort<%= tmpOrder %>.gif" width="10" height="15"> 
              <% end if %>
              </b></font><font color="#000000"></font></div>
          </td>
          <td width="9%" height="25"> 
            <div align="center"><font color="#000066"><b>Payment Date </b></font><font color="#000000"></font></div>
          </td>
          <td width="4%" height="25"> 
            <div align="center"><font color="#000000"><b><font color="#000066">Curr.</font></b></font></div>
          </td>
          <td width="10%" height="25"> 
            <div align="center"><font color="#000066"><b><a href="#" class="menu" onClick="return DoSort('SUBTOTAL','<%= CurrOrder %>')">Amount</a> 
              <% if (tmpSort="SUBTOTAL") then %>
              <img src="images/imgSort<%= tmpOrder %>.gif" width="10" height="15"> 
              <% end if %>
              </b></font><font color="#000000"></font></div>
          </td>
          <td height="25"> 
            <div align="center"><font color="#000000"><b><a href="#" onClick="return DoSort('VENDORID','<%= CurrOrder %>')" class="menu">Vendor</a></b></font><font color="#000066"><b> 
              <% if (tmpSort="VENDORID") then %>
              <img src="images/imgSort<%= tmpOrder %>.gif" width="10" height="15"> 
              <% end if %>
              </b></font></div>
          </td>
          <td width="15%" height="25" align="center"><b><font color="#000066">Location</font></b></td>
          <td width="8%" height="25"> 
            <div align="center"><b><font color="#000066">Status</font></b></div>
          </td>
        </tr>
        <% dim j 
		j = 1 %>
        <% 
While ((Repeat2__numRows <> 0) AND (NOT LVO.EOF)) 
%>
        <% if ((j mod 2 ) <> 0 ) Then %>
        <tr bgcolor="#FFFFFF"> 
          <td width="5%"> 
            <div align="right"><%= j + LVO_first -1 %>.&nbsp;</div>
          </td>
          <td width="7%"> 
            <div align="center"><b><a href="#"  onClick="return redirect('<%=(LVO.Fields.Item("LVONUM").Value)%>')"><%=(LVO.Fields.Item("REGNUM").Value)%></a></b></div>
          </td>
          <td width="10%"><%=(LVO.Fields.Item("INVNUM").Value)%></td>
          <td width="9%"> 
            <div align="center"><%=(LVO.Fields.Item("LVONUM").Value)%></div>
          </td>
          <td width="9%"> 
            <div align="center"><%= DoDateTime((LVO.Fields.Item("PAYMENTDATE").Value), 2, 2070) %></div>
          </td>
          <td width="4%"> 
            <div align="center"><%=(LVO.Fields.Item("SYMBOL").Value)%></div>
          </td>
          <td width="10%"> 
            <div align="right"><%= FormatNumber((LVO.Fields.Item("SUBTOTAL").Value), -1, -2, -2, -1) %></div>
          </td>
          <td><%=(LVO.Fields.Item("VENDORNAME").Value)%></td>
          <td width="15%"><%=(LVO.Fields.Item("LOCNAME").Value)%></td>
          <td> 
            <div align="center"><%=(LVO.Fields.Item("STATUS").Value)%></div>
          </td>
        </tr>
        <% else %>
        <tr bgcolor="#eeeeee"> 
          <td width="5%"> 
            <div align="right"><%= j + LVO_first - 1 %>.&nbsp;</div>
          </td>
          <td width="7%"> 
            <div align="center"><b><a href="#" onClick="return redirect('<%=(LVO.Fields.Item("LVONUM").Value)%>')"><%=(LVO.Fields.Item("REGNUM").Value)%></a></b></div>
          </td>
          <td width="10%"><%=(LVO.Fields.Item("INVNUM").Value)%></td>
          <td width="9%"> 
            <div align="center"><%=(LVO.Fields.Item("LVONUM").Value)%></div>
          </td>
          <td width="9%"> 
            <div align="center"><%= DoDateTime((LVO.Fields.Item("PAYMENTDATE").Value), 2, 2070) %></div>
          </td>
          <td width="4%"> 
            <div align="center"><%=(LVO.Fields.Item("SYMBOL").Value)%></div>
          </td>
          <td width="10%"> 
            <div align="right"><%= FormatNumber((LVO.Fields.Item("SUBTOTAL").Value), -1, -2, -2, -1) %></div>
          </td>
          <td><%=(LVO.Fields.Item("VENDORNAME").Value)%></td>
          <td width="15%"><%=(LVO.Fields.Item("LOCNAME").Value)%></td>
          <td> 
            <div align="center"><%=(LVO.Fields.Item("STATUS").Value)%></div>
          </td>
        </tr>
        <% end if %>
        <% j = j +1
  Repeat2__index=Repeat2__index+1
  Repeat2__numRows=Repeat2__numRows-1
  LVO.MoveNext()
Wend
%>
      </table>
    </td>
  </tr>
  <tr> 
    <td width="4%">&nbsp;</td>
    <td width="2%" bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF">&nbsp;</td>
  </tr>
</table>
</body>
</html>
<%
LVO.Close()
%>
